package killerqueen.game.main;

import org.jbox2d.callbacks.ContactImpulse;
import org.jbox2d.callbacks.ContactListener;
import org.jbox2d.collision.Manifold;
import org.jbox2d.dynamics.Fixture;
import org.jbox2d.dynamics.contacts.Contact;

public class GameContactListener implements ContactListener {

	public GameContactListener() {

	}

	@Override
	public void beginContact(Contact contact) {
		Fixture fixture = contact.getFixtureA();

		Object userData = fixture.getUserData();

		if (userData instanceof ContactListener) {
			ContactListener contactListener = (ContactListener) userData;
			contactListener.beginContact(contact);
		}

		fixture = contact.getFixtureB();

		userData = fixture.getUserData();

		if (userData instanceof ContactListener) {
			ContactListener contactListener = (ContactListener) userData;
			contactListener.beginContact(contact);
		}
	}

	@Override
	public void endContact(Contact contact) {
		Fixture fixture = contact.getFixtureA();

		Object userData = fixture.getUserData();

		if (userData instanceof ContactListener) {
			ContactListener contactListener = (ContactListener) userData;
			contactListener.endContact(contact);
		}

		fixture = contact.getFixtureB();

		userData = fixture.getUserData();

		if (userData instanceof ContactListener) {
			ContactListener contactListener = (ContactListener) userData;
			contactListener.endContact(contact);
		}
	}

	@Override
	public void postSolve(Contact arg0, ContactImpulse arg1) {
		// TODO Auto-generated method stub

	}

	@Override
	public void preSolve(Contact arg0, Manifold arg1) {
		// TODO Auto-generated method stub

	}

}
